home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Alles Voor Internet / Tout Pour Internet
/
alles voor internet.iso
/
MacInternet™
/
Telnet
/
NCSA
/
tn3270 2.4d7 source
/
NCSA⁄BYU TCP⁄IP
/
croft.c
< prev
next >
Wrap
Text File
|
1991-10-02
|
8KB
|
387 lines
#ifndef lint
static char *SCCSid = "%W% (NCSA) %G%";
#endif
/*
* croft.c
* by Gaige B. Paulsen
****************************************************************************
* *
* Uses : *
* TCP/IP kernel for NCSA Telnet *
* by Tim Krauskopf *
* with Macintosh code by Gaige B. Paulsen *
* *
* National Center for Supercomputing Applications *
* 152 Computing Applications Building *
* 605 E. Springfield Ave. *
* Champaign, IL 61820 *
* *
* *
****************************************************************************
*
* KIP/Croft gateway handling code.
*
* Called by:
* maclook.c
* mactools.c
* macutil.c
*/
#include <stdio.h>
#include <string.h>
#include <AppleTalk.h>
#include <Dialogs.h>
#include <Memory.h>
#include <Strings.h>
#include "configrec.h"
#include "kip.h"
#include "maclook.h"
#include "mpw.h"
extern void OtherError(); /* BYU */
#ifdef OLDM
struct NBPentadd {
AddrBlock addr;
EntityName entity;
};
typedef struct NBPentadd NBPentadd;
NBPRecHdl
myRecH; /* Handle used for AB records */
#endif OLDM
char
KIPzone[33]="\p*", /* Kip zone in P-string */
*KIPnameptr=0L; /* Pointer to current name block (NBP) */
void KIPunregister
(
void
)
{
MPPParamBlock Mpb;
int i;
char temp[50];
Mpb.NBPentityPtr = &KIPnameptr[9];
i =PRemoveName(&Mpb, FALSE);
sprintf(temp, "RN=%d",i);
putln(temp);
}
#ifdef DEBUGG
/*
* NBPdisplay- display an NBP packet (eap) in a reasonable format
*
*/
NBPdisplay( eap)
NTElement *eap;
{
unsigned char *cp;
int len1,len2;
cp=(char *)eap+3;
len1= cp[1];
len2= cp[ len1+2];
printf("Name: %*s\nType: %*s\nZone: *\nAtalk Address: %d.%d.%d\n",
len1,&cp[2], len2, &cp[ len1+3],
eap->nteAddress.aNet, eap->nteAddress.aNode, eap->nteAddress.aSocket);
}
#endif DEBUGG
/*
* NBPfind - check for <object,typename,zone> wikth the resultant address
* in buffer which is bufsize bytes. Expect expect responses.
*
* returns <0 if NBP/network error
* =0 if not found
* >0 if ok
*/
int NBPfind( object,typename,zone, buffer,bufsize, expect,rti)
Str32 *object, *typename, *zone;
char *buffer;
int rti,expect,bufsize;
{
MPPParamBlock Mpb;
EntityName entity;
int err;
NBPSetEntity((Ptr) &entity, (Ptr) object, (Ptr) typename, (Ptr) zone);
Mpb.NBPentityPtr = (Ptr) &entity;
Mpb.NBPretBuffPtr=buffer;
Mpb.NBPretBuffSize=bufsize;
Mpb.NBPmaxToGet=expect;
Mpb.NBPinterval= rti;
Mpb.NBPcount = 4;
err= PLookupName(&Mpb, FALSE);
if (err!=0) {
putln("Error in NBP Lookup.....%d\n");
return(-1);
}
else return(Mpb.NBPnumGotten);
}
/*
* NBPregister - Register on the network as <object,typename,zone> using
* buffer of size to store permanent information.
*
* returns <0 if NBP/network error
* >=0 if ok
*/
int NBPregister( object,typename,zone, buffer,size )
Str32 *object, *typename, *zone;
NamesTableEntry *buffer;
int size;
{
#pragma unused(size)
MPPParamBlock Mpb;
int err;
THz curzone;
if (KIPnameptr)
KIPunregister();
curzone = GetZone();
SetZone(SystemZone());
(Ptr) KIPnameptr = (Ptr) buffer = NewPtr((long)sizeof(NamesTableEntry));
SetZone(curzone);
NBPSetNTE((Ptr) buffer, (Ptr) object, (Ptr) typename, (Ptr) zone, 72);
Mpb.NBPntQElPtr = (Ptr) buffer;
Mpb.NBPinterval= 5;
Mpb.NBPcount = 5;
Mpb.NBPverifyFlag=1;
err= PRegisterName(&Mpb, FALSE);
if (err!=0) {
putln("Error in NBP Register.....%d\n");
DisposPtr((Ptr) buffer);
return(-1);
}
else return(Mpb.MPPioResult);
}
/*
* ATPsend - sends a request to the ATP server at addr using the packet in
* buffer which is size bytes long puting the return data in the
* retdata BDS.
*
* returns <0 if ATP/network error
* >=0 if ok
*/
ATPsend( addr, buffer, size, retdata)
AddrBlock *addr;
char *buffer;
int size;
BDSPtr retdata;
{
ATPParamBlock Apb;
int err;
Apb.ATPaddrBlock=*addr;
Apb.ATPreqLength=size;
Apb.ATPreqPointer=buffer;
Apb.ATPbdsPointer = (Ptr) retdata;
Apb.ATPatpFlags=0;
Apb.ATPtimeOutVal=5;
Apb.ATPretryCount=4;
Apb.ATPnumOfBuffs=1;
err=PSendRequest( &Apb, FALSE);
return(err);
}
/*
* KIParp - Use the croft code to arp for machine with the IP number ipnum,
* returning the AT address in addrloc.
*
* returns <0 if NBP/network error
* >=0 if ok
*/
int KIParp
(
unsigned char ipnum[4],
AddrBlock *addrloc
)
{
NTElement retbuff;
int ret;
char temps[20];
sprintf(temps," %d.%d.%d.%d", (int)ipnum[0],(int)ipnum[1],(int)ipnum[2],
(int)ipnum[3]);
#ifdef DEBUGG
puts(temps); puts(" is being looked up\n");
#endif
temps[0]=strlen(temps)-1;
ret=NBPfind( temps,"\pIPADDRESS",KIPzone,&retbuff,sizeof(retbuff),1,40);
#ifdef DEBUGG
NBPdisplay(&retbuff);
#endif DEBUGG
*addrloc=retbuff.nteAddress;
return(ret);
}
/*
* KIPregister - Use the croft code to register our machine on the network as
* ipno.
*
* returns <0 if NBP/network error
* >=0 if ok
*/
int KIPregister
(
unsigned char *ipnum
)
{
char temps[20];
int ret;
sprintf(temps," %d.%d.%d.%d", (int)ipnum[0],(int)ipnum[1],(int)ipnum[2],
(int)ipnum[3]);
#ifdef DEBUGG
puts(temps); puts(" is being registered \n");
#endif
#ifdef DONTDOTHISRIGHTNOW
KIPnameptr=NewPtr(110);
if (KIPnameptr==0L) return(-1);
#endif
temps[0]=strlen(temps)-1;
ret=NBPregister( temps, "\pIPADDRESS", KIPzone , KIPnameptr,110);
return(ret);
}
/*
* KIPgetdynam - Use the croft code to get a dynamic IP number for us from
* the server at servAddr. The IP number is stored in IPaddr.
*
* returns <0 if NBP/network error
* >=0 if ok
*/
int KIPgetdynam
(
AddrBlock *servAddr,
long *IPaddr
)
{
IPGP gateRec,gateSend;
BDSType retBDS;
int err;
retBDS[0].buffSize=sizeof(gateRec);
retBDS[0].buffPtr = (Ptr) &gateRec;
gateSend.opcode=ipgpAssign;
err=ATPsend( servAddr, &gateSend,sizeof(gateSend), retBDS);
if (err!=0)
{
*IPaddr = 0L;
#ifndef MPW
OtherError("\PUnable to get dynamic IP number","\P ");
#else
OtherError("Unable to get dynamic IP number"," ");
#endif MPW
return(err);
}
*IPaddr=gateRec.ipaddress;
#ifdef DEBUGG
if (gateRec.opcode<0) puts(gateRec.string);
#endif
return(0);
}
/*
* KIPgetns - Use the croft code to get the IP number of the Nameserver for us from
* the server at servAddr. The IP number is stored in IPaddr.
*
* returns <0 if NBP/network error
* >=0 if ok
*/
int KIPgetns
(
AddrBlock *servAddr,
long *IPaddr
)
{
IPGP gateRec,gateSend;
BDSType retBDS;
int err;
retBDS[0].buffSize=sizeof(gateRec);
retBDS[0].buffPtr = (Ptr) &gateRec;
gateSend.opcode=ipgpServer;
err=ATPsend( servAddr, &gateSend,sizeof(gateSend), retBDS);
if (err!=0) return(err);
*IPaddr=gateRec.ipname;
#ifdef DEBUGG
if (gateRec.opcode<0) puts(gateRec.string);
#endif
return(0);
}
/*
* KIPfindgate - Use the croft code to find a gateway to use. Returns the
* AT address in addr.
*
* returns <0 if NBP/network error
* =0 if there are none.
* >0 if ok
*/
int KIPfindgate
(
AddrBlock *addr
)
{
NTElement retbuff;
int ret;
ret=NBPfind( "\p=","\pIPGATEWAY", KIPzone,&retbuff,sizeof(retbuff),1,3);
#ifdef DEBUGG
NBPdisplay(&retbuff);
#endif DEBUGG
*addr=retbuff.nteAddress;
return(ret);
}
/* KIPsetzone - set up KIPzone */
void KIPsetzone
(
char *zone
)
{
strncpy(KIPzone,zone,32); /* Copy incoming */
KIPzone[32]=0; /* NUL terminate */
c2pstr(KIPzone); /* Convert to pascal string */
putln("new zone is:");
putln(zone);
}